package com.lmscn.lms.api.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

/**
 * 课程与分类关联表
 * 
 * @author zhang.xx
 * @date 2016年12月29日10:15:40
 */
public class CourseCategoryRelated extends Model<CourseCategoryRelated> {

	public static final CourseCategoryRelated dao = new CourseCategoryRelated();
	
	
	/**
	 * 获取关联列表
	 * 
	 * @param courseCategoryId
	 * @return
	 */
	public List<CourseCategoryRelated> listByCategoryId(Long courseCategoryId, int pageNumber, int pageSize) {
        return dao.find("select t.* from t_course_category_related t"
        		+ " where t.category_id = ? order by t.seq desc limit "
        		+ (pageNumber-1)*pageSize + "," + pageSize, courseCategoryId);
	}
	
	/**
	 * 获取关联列表
	 * 
	 * @param courseCategoryId
	 * @return
	 */
	public Page<CourseCategoryRelated> getByCategoryId(Long courseCategoryId, int pageNumber, int pageSize) {
		return dao.paginate(pageNumber, pageSize, "select t.* ",
				" from t_course_category_related t where t.category_id = ? order by seq desc ", courseCategoryId);
	}
	
	/**
	 * 获取分类下课程数量
	 * 
	 * @param courseCategoryId
	 * @return
	 */
	public Long getCourseCount(Long courseCategoryId) {
		return Db.queryLong("select count(id) from t_course_category_related where category_id = ?", courseCategoryId);
	}

}
